<template>
  <div>
    <el-card class="box-card" v-model="user">
      <div class="text item informationItem">姓名:{{ user.name }}</div>
      <div class="text item informationItem">学号:{{ user.number }}</div>
      <div class="text item informationItem">专业:{{ user.professional }}</div>
    </el-card>
    <el-button type="primary" @click="toIndex">回到首页</el-button>
  </div>
</template>

<style>
* {
  margin: 0;
  padding: 0;
}
.text {
  font-size: 18px;
}

.item {
  padding: 18px 0;
  
}
.informationItem {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  justify-content: center;
}
.box-card {
  width: 10rem;
  margin: 1rem auto;
}
</style>

<script>
import axios from "axios";
import { del, get } from "@/utils/request";

export default {
  data() {
    return { userInfo: {}, userId: "", user: {} };
  },
  methods: {
    toIndex() {
      this.$router.replace("/");
    },
    async getInfo() {
      let url = "http://120.77.41.127:8080/nameUser/query";
      let data = await get(url);
      this.userInfo = data.data;
      this.userId = sessionStorage.getItem("userId");
      console.log(this.userInfo);
      if (this.userId == null) {
        return;
      } else {
        for (let i = 0; i < this.userInfo.length; i++) {
          if (this.userInfo[i].id == this.userId) {
            this.user = this.userInfo[i];
            break;
          }
        }
      }
    }
  },
  mounted() {
    this.getInfo();
  }
};
</script>